# vim:ts=4:sw=4:noet:
"""
Class property helper
"""

import sys

def attribute(name, permit='rw', fget=None, fset=None, doc=''):
	if _isprivate(name):
		name = "_%s%s" % (_get_classname(), name)
	if 'r' in permit and fget is None:
		fget = lambda self: getattr(self, name)
	if 'w' in permit and fset is None:
		fset = lambda self, value: setattr(self, name, value)
	fdel = lambda self: delattr(self, name)
	return property(fget, fset, fdel, doc)

def _isprivate(name):
	return name.startswith("__") and not name.endswith("__")

def _get_classname():
	frame = sys._getframe(2)
	return frame.f_code.co_name
